package android.medicalcloud.com.yiapp.yilian.ui;

import android.medicalcloud.com.yiapp.R;
import android.medicalcloud.com.yiapp.base.activity.BaseActivity;
import android.medicalcloud.com.yiapp.base.net.lisener.ViewNetCallBack;
import android.medicalcloud.com.yiapp.base.utils.ListUtil;
import android.medicalcloud.com.yiapp.base.utils.Logger;
import android.medicalcloud.com.yiapp.base.utils.StringTools;
import android.medicalcloud.com.yiapp.yilian.logic.PatientController;
import android.medicalcloud.com.yiapp.yilian.model.CaseModel;
import android.medicalcloud.com.yiapp.yilian.model.PatitentAllModel;
import android.medicalcloud.com.yiapp.yilian.model.PatitentModel;
import android.medicalcloud.com.yiapp.yilian.ui.view.CommonTitleView;
import android.medicalcloud.com.yiapp.yilian.ui.view.adapter.FileAdapter;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.Serializable;

/**
 * Created by wanggenlin on 17-5-18.
 */
public class PatientDetailActivity extends BaseActivity implements ViewNetCallBack {
    TextView nameTv,sexTv,ageTv,jibingTv,decript;
    TextView zhaiyaoTv,huayanTv,yingxiangTv,otherTv,zhanduanTv,jianjieTv;
    View filesLayout;
    GridView filesGV;
    FileAdapter adapter;
    @Override
    protected void initView() {
        CommonTitleView   titleView =(CommonTitleView) findViewById(R.id.titleView);
        titleView.setTitleText("病人详情");

         nameTv = (TextView) findViewById(R.id.nameTv);
         sexTv = (TextView) findViewById(R.id.sexTv);
         ageTv = (TextView) findViewById(R.id.ageTv);
         jibingTv = (TextView) findViewById(R.id.jibingTv);
         decript = (TextView) findViewById(R.id.decript);
        zhaiyaoTv = (TextView) findViewById(R.id.zhaiyaoTv);
        huayanTv = (TextView) findViewById(R.id.huayanTv);
        yingxiangTv = (TextView) findViewById(R.id.yingxiangTv);
        otherTv = (TextView) findViewById(R.id.otherTv);
        zhanduanTv = (TextView) findViewById(R.id.zhanduanTv);
        jianjieTv = (TextView) findViewById(R.id.jianjieTv);
        filesLayout =  findViewById(R.id.filesLayout);
        filesGV =  (GridView)findViewById(R.id.filesGV);
        adapter = new FileAdapter(this);
        filesGV.setAdapter(adapter);
    }

    @Override
    protected void initEvent() {
       PatitentModel m = (PatitentModel) getIntent().getSerializableExtra("m");
        if (m==null){
            finish();
            return;
        }
        nameTv.setText("病人姓名："+m.getName());
        sexTv.setText("性别："+m.getSex());
        ageTv.setText("年龄："+m.getAge());
        jibingTv.setText("确诊疾病："+m.getDisease());
        decript.setText(m.getSimpleDescribe());
        PatientController.getInstance().detail(this,m.getId());

//        PatientController.getInstance().detail(this,"43");
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.ac_patient;
    }

    @Override
    public void onConnectStart(Object o) {

    }

    @Override
    public void onConnectEnd() {

    }

    @Override
    public void onFail(Exception e, Object o, String reslut) {

    }

    @Override
    public void onData(Serializable result, int flag, boolean fromNet, Object o) {

        Logger.e(o.toString());
        PatitentAllModel m = (PatitentAllModel)result;
        CaseModel caseModel = m.getPatient().getModel();
        Logger.e("case=="+caseModel);
        zhaiyaoTv.setText("病历摘要: "+caseModel.getCaseAbstract());
        huayanTv.setText("化　　验: "+caseModel.getTest());
        yingxiangTv.setText("影像检查情况: "+caseModel.getImageReport());
        otherTv.setText("其他检查报告: "+caseModel.getOtherReprot());
        zhanduanTv.setText("诊断及依据: "+caseModel.getDiagnosis());
        jianjieTv.setText("治疗情况简介: "+caseModel.getSummy());
        decript.setText(""+m.getPatient().getDescribe());
        findViewById(R.id.caseLayout).setVisibility(StringTools.isNullOrEmpty(caseModel.getSummy())?View.GONE:View.VISIBLE);
        findViewById(R.id.filesLayout).setVisibility(ListUtil.isNullOrEmpty(caseModel.getFiles())?View.GONE:View.VISIBLE);
        Logger.e("fils=="+caseModel.getFiles().size());
        adapter.setRes(caseModel.getFiles());
    }
}
